package user_service

import (
	"context"
)

type User struct {
	Id       string `json:"id"`
	Name     string `json:"name"`
	Username string `json:"username"`
	Email    string `json:"email"`
	Password string `json:"password"`
	Age      int    `json:"age"`
}

type GetUserByIdRequest struct {
	Id string `json:"id"`
}

type GetUserByIdResponse struct {
	Data *User `json:"data"`
}

type UserService struct {
}

func (u *UserService) GetUserById(ctx context.Context, req *GetUserByIdRequest) (*GetUserByIdResponse, error) {
	id := req.Id
	res := &GetUserByIdResponse{}

	// 去查找对应id的user, 找到后返回
	// mock 找到的user
	us := &User{Id: id, Name: "zly", Username: "zly2", Email: "123", Age: 23}

	res.Data = us
	return res, nil
}

func (u *UserService) TestTimeout(ctx context.Context, req *GetUserByIdRequest) (*GetUserByIdResponse, error) {
	select {
	case <-ctx.Done():
		return nil, ctx.Err()
	}
}

func (u *UserService) Name() string {
	return "user_service"
}
